package mo.tags.greedy;

import java.util.Arrays;

public class L955 {

    public int minDeletionSize(String[] strs) {
        int w = strs.length;
        int n = strs[0].length();
        int ans = 0;

        String[] cur = new String[w];
        for (int i = 0; i < n; i++) {
            String[] cur2 = Arrays.copyOf(cur, w);
            for (int j = 0; j < w; j++) {
                cur2[j] += strs[j].charAt(i);
            }
            if (isSorted(cur2)) {
                cur = cur2;
            } else {
                ans++;
            }
        }
        return ans;
    }

    private boolean isSorted(String[] cur) {
        for (int i = 0; i < cur.length-1; i++) {
            if (cur[i].compareTo(cur[i+1]) > 0) {
                return false;
            }
        }
        return true;
    }

}
